<template>
	<view>
		<u-navbar :title="pageTitle" title-color="#FFF" :background="navBackground" :is-fixed="true" :border-bottom="false" :is-back="true" back-icon-color="#FFF"></u-navbar>
		<view class="content" v-if="detailsData">
			<view class="content">{{ detailsData.result }}</view>
			<view class="d-flex-center change w-100 z-fixed"><text @click="getDetails">换一个</text></view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			navBackground: this.$navBackground,
			pageTitle:'',
			pageType: '',
			detailsData: ''
		};
	},
	onLoad(option) {
		this.pageType = option.type;
		this.pageTitle = option.name;
		this.getDetails();
	},
	methods: {
		getDetails() {
			let _this = this;
			uni.showLoading();
			// 调用微信小程序三方服务接口api
			wx.serviceMarket
				.invokeService({
					service: 'wxcae50ba710ca29d3',
					api: 'jokebot',
					data: {
						mode: _this.pageType
					}
				})
				.then(res => {
					uni.hideLoading();
					console.log('invokeService success', res);
					if (res.data.err_code == 0) {
						_this.detailsData = res.data.data_list[0];
					} else {
						_this.$tools.showToast('请稍后再试~');
					}
				})
				.catch(err => {
					uni.hideLoading();
					_this.$tools.showToast('请稍后再试~');
					console.error('invokeService fail', err);
				});
		}
	}
};
</script>

<style lang="scss">
.content {
	padding: 20rpx 32rpx;
	.box {
		padding: 0 30rpx;
	}
	.change {
		bottom: 80rpx;
		left: 0;
	}
}
</style>
